package com.bjx.system.controller;

import com.bjx.common.core.domain.R;
import com.bjx.api.system.domain.vo.DictDataVO;
import com.bjx.system.service.IDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @desc: 字典数据控制器
 * @author: liushuai
 * @date: 2022/8/16 11:37
 */
@RestController
@Tag(name = "字典数据控制器")
@RequestMapping("/dict/data")
public class DictDataController {
    @Autowired
    private IDictDataService dictDataService;


    /**
     * 根据字典类型编号查询字典数据
     * @param dictTypeCode
     * @return: com.bjx.common.core.domain.R<java.util.List<com.bjx.system.domain.vo.DictDataVO>>
     * @Author: liushuai
     * @Date: 2022/8/16
     */
    @Operation(summary = "根据字典类型编号查询字典数据列表")
    @GetMapping("listDictDataByDictTypeCode")
    public R<List<DictDataVO>> listDictDataByDictTypeCode(@RequestParam String dictTypeCode){
       List<DictDataVO> list = dictDataService.listDictDataByDictTypeCode(dictTypeCode);
       return R.success(list);
    }


    /**
     * 根据字典类型编号缓存加载业务字典数据
     * @param dictTypeCode
     * @return: com.bjx.common.core.domain.R<java.util.List<com.bjx.api.system.domain.vo.DictDataVO>>
     * @Author: liushuai
     * @Date: 2022/9/29
     */
    @Operation(summary = "根据字典类型编号缓存加载业务字典数据")
    @GetMapping("listCacheDictDataByDictTypeCode")
    public R<List<DictDataVO>> listCacheDictDataByDictTypeCode(@RequestParam String dictTypeCode){
        List<DictDataVO> list = dictDataService.listCacheDictDataByDictTypeCode(dictTypeCode);
        return R.success(list);
    }

    /**
     * 根据字典类型编号清除缓存字典
     * @param dictTypeCode
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/10/11
     */
    @Operation(summary = "根据字典类型编号清除缓存字典")
    @GetMapping("clearCacheByDictTypeCode")
    public R clearCacheByDictTypeCode(@RequestParam String dictTypeCode){
        dictDataService.clearCacheByDictTypeCode(dictTypeCode);
        return R.successMsg("缓存清理成功");
    }


}
